/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fullalbum;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author leoomoreira
 */
public abstract class GenericServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        if (session == null || session.getAttribute("userId") == null) {
            RequestDispatcher dispatcher = req.getRequestDispatcher("LogoutServlet");
            dispatcher.forward(req, resp);
        } else {
            processRequest(req, resp);
        }
    }

    protected abstract void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException;
}
